package fei.yuzhi.com.loveflowers.fragment.classifyFragment;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import fei.yuzhi.com.loveflowers.R;
import fei.yuzhi.com.loveflowers.bean.ClassifyItemBean;

/**
 * Created by Administrator on 2016/10/8.
 */
public class ClassifyItemAdapter extends BaseAdapter {
    private List<ClassifyItemBean.DatasBean.ClassListBean.ChildBean> list;
    private Context context;
    private Handler handler=new Handler();
    public ClassifyItemAdapter(List<ClassifyItemBean.DatasBean.ClassListBean.ChildBean> list,Context context){
        this.list=list;
        this.context=context;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.gridview_classify,null);
            holder=new ViewHolder();
            holder.tv_classifygridview= (TextView) convertView.findViewById(R.id.tv_classifygridview);
            holder.iv_classifygridview= (ImageView) convertView.findViewById(R.id.iv_classifygridview);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
            holder.tv_classifygridview.setText(list.get(position).getGcName());
             String str=list.get(position).getGcImage();
            Picasso.with(context).load(str).into(holder.iv_classifygridview);
        }
        return convertView;
    }
    static class ViewHolder{
        TextView tv_classifygridview;
        ImageView iv_classifygridview;
    }
}
